import {instance as axios} from "./config.service";
import store from "../../store/store";

export const getFaults = (per_page= 100, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/faultList.json',
        url: '/faults',
        method: 'get',
        params: {per_page, page_no, include: 'vehicle'},
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};

export const getTeamMembers = (per_page= 100, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/teamList.json',
        url: '/members',
        method: 'get',
        params: {per_page, page_no},
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};

export const getVehicles = (per_page= 100, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/vehicleList.json',
        url: '/vehicles',
        method: 'get',
        params: {per_page, page_no},
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};

export const getTools = (per_page= 100, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/toolsList.json',
        url: 'tools',
        method: 'get',
        params: {per_page, page_no, include: 'vehicle'},
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};

export const getRoutes = (per_page= 100, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/routeList.json',
        url: '/routes',
        method: 'get',
        params: {
            per_page,
            page_no,
            include: 'source_address,destination_address,route_planner,route_planner.route_stops'
        },
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};

export const getProducts = (per_page= 100, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/productList.json',
        url: '/products',
        method: 'get',
        params: {per_page, page_no, include: 'product_routes,product_routes.route_rate'},
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};

export const getAddresses = (per_page= 90, page_no = 1) => {
    const API_DETAILS = {
        // baseURL: '/stub/addressList.json',
        url: '/addresses',
        method: 'get',
        params:{per_page, page_no},
        headers: {'Authorization': `Bearer ${store.getState().auth.token}`}
    };
    return axios(API_DETAILS);
};
